package com.sample.classes.testing;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewStub;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.OnNavigationListener;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.MenuItem;
import com.apps.realtyportal.HomeActivity;
import com.apps.realtyportal.R;
import com.apps.realtyportal.R.drawable;
import com.apps.realtyportal.R.id;
import com.apps.realtyportal.R.layout;
import com.apps.realtyportal.R.menu;

public class DummyActivity extends SherlockActivity {

	private ActionBar actionbar;

	String string = "Property Portal";
	String[] actions = new String[] { "Property Portal", "Bookmark",
			"Subscribe", "Share" };
	String[] entries = new String[] { "Property Portal", "View Card",
			"Favorites", "Settings" };

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_listing_board);

		actionbar = getSupportActionBar();
		actionbar.setDisplayShowHomeEnabled(true);
		actionbar.setDisplayShowTitleEnabled(false);

		actionbar.setDisplayHomeAsUpEnabled(true);

		actionbar.setDisplayShowCustomEnabled(true);
		View actionbar1 = LayoutInflater.from(this).inflate(
				R.layout.action_custom, null);
		actionbar.setCustomView(actionbar1);

		// setTheme(com.actionbarsherlock.R.style.Sherlock___Widget_Holo_Spinner);
		// setHeader(getString(R.string.HomeActivityTitle), false, true);
		// getSupportActionBar().setDisplayShowHomeEnabled(false);
		// getSupportActionBar().setDisplayShowTitleEnabled(false);
		//
		// ArrayAdapter<CharSequence> adapter = new
		// ArrayAdapter<CharSequence>(this, R.string.app_name,
		// R.layout.sherlock_spinner_dropdown_item,
		// getResources().getStringArray(R.array.list_down));

		// SpinnerAdapter adapter = ArrayAdapter.createFromResource(
		// getApplicationContext(), R.array.list_down,
		// android.R.layout.simple_spinner_dropdown_item);

		// TODO attach to an adapter of some sort
		// getSupportActionBar().setCustomView(spinner);
		// getSupportActionBar().setDisplayShowCustomEnabled(true);

		/** Create an array adapter to populate dropdownlist */

		ArrayAdapter<String> adapter = new ArrayAdapter<String>(
				getBaseContext(), R.layout.sherlock_spinner_item);

		adapter.add("Property Portal");
		adapter.add("View Card");
		adapter.add("Favorites");
		adapter.add("Settings");

		// ArrayAdapter<String> adapter_list = new ArrayAdapter<String>(
		// getApplicationContext(), R.layout.sherlock_spinner_item,
		// entries);
		//
		/** Enabling drop down list navigation for the action bar */
		getSupportActionBar().setNavigationMode(
				com.actionbarsherlock.app.ActionBar.NAVIGATION_MODE_LIST);

		/** Defining Navigation listener */

		ActionBar.OnNavigationListener navigationListener = new OnNavigationListener() {
			public boolean onNavigationItemSelected(int itemPosition,
					long itemId) {
				Toast.makeText(getBaseContext(),
						"Current Action : " + entries[itemPosition],
						Toast.LENGTH_SHORT).show();
				return false;
			}
		};

		/**
		 * Setting dropdown items and item navigation listener for the actionbar
		 */

		// getSupportActionBar().setListNavigationCallbacks(adapter,
		// navigationListener);
		// adapter.remove("Property Portal");
		// adapter.notifyDataSetChanged();
		getSupportActionBar().setListNavigationCallbacks(adapter,
				navigationListener);
		((ArrayAdapter<?>) adapter)
				.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);

		// getSupportActionBar().setDisplayOptions(
		// ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_USE_LOGO
		// | ActionBar.DISPLAY_SHOW_HOME);

		// initIds();
	}

	@Override
	public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
		// getMenuInflater().inflate(R.menu.activity_home, menu);
		// return true;

		getSupportMenuInflater().inflate(R.menu.activity_home, menu);

		/* Add an expandable Search Icon in the ActionBar */
		menu.add("Search")
				.setIcon(R.drawable.four)
				.setShowAsAction(
						MenuItem.SHOW_AS_ACTION_IF_ROOM
								| MenuItem.SHOW_AS_ACTION_WITH_TEXT);

		menu.add("Direction").setIcon(R.drawable.two)
				.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

		menu.add("Favorites").setIcon(R.drawable.one)
				.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

		menu.add("Queries").setIcon(R.drawable.three)
				.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

		/* Set up action overflow menus */
		// SubMenu subMnuOverFlow = menu.addSubMenu("Overflow");
		// subMnuOverFlow.add("Settings");
		// subMnuOverFlow.add("About");
		// subMnuOverFlow.add("Exit");
		//
		// /* Add the menus */
		// MenuItem actionOverFlow = subMnuOverFlow.getItem();
		//
		// actionOverFlow.setIcon(R.drawable.ic_action_overflow);
		// actionOverFlow.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

		return super.onCreateOptionsMenu(menu);
	}

	/**
	 * Button click handler on Main activity
	 * 
	 * @param v
	 */

	public void setHeader(String title, boolean btnHomeVisible,
			boolean btnFeedbackVisible) {
		ViewStub stub = (ViewStub) findViewById(R.id.vsHeader);
		View inflated = stub.inflate();

		TextView txtTitle = (TextView) inflated.findViewById(R.id.txtHeading);
		txtTitle.setText(title);

		Button btnHome = (Button) inflated.findViewById(R.id.btnHome);
		if (!btnHomeVisible)
			btnHome.setVisibility(View.INVISIBLE);

	}

	/**
	 * This callback method will be invoked when the user selects up navigation
	 * icon from the action bar
	 */
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			Intent intent = new Intent(this, HomeActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
			startActivity(intent);
		}
		return super.onOptionsItemSelected(item);
	}

}